package com.pattern.structural.adaptor;

/**
 * @Description  client to use adapter.
 * @Author Ping
 * @Date 2022/3/28 15:47
 **/
public class Computer {
    private EUsedElectricity eUsedElectricity ;

    public Computer(EUsedElectricity eUsedElectricity) {
        this.eUsedElectricity = eUsedElectricity;
    }

    public void seteUsedElectricity(EUsedElectricity eUsedElectricity) {
        this.eUsedElectricity = eUsedElectricity;
    }

    public void doCharge() {
        System.out.println("the computer run out of power.") ;
        eUsedElectricity.chargedWith20V();
        System.out.println("the computer got power again!");
    }

    public static void main(String args[]) {
        // example for class-type adapter .
        Computer computer = new Computer(new EClassAdapter()) ;
        computer.doCharge();
        // an example for object adapter .
        EUsedElectricity eObjectAdapter = new EObjectAdapter(new HomeUsedElectricity()) ;
        computer.seteUsedElectricity(eObjectAdapter);
        computer.doCharge();

     }

}
